package com.pethospital.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.pethospital.common.Result;
import com.pethospital.dto.ReviewDTO;
import com.pethospital.entity.Review;
import com.pethospital.entity.Staff;
import com.pethospital.service.HospitalInfoService;
import com.pethospital.service.StaffService;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.validation.Valid;
import java.util.Map;

/**
 * 医院信息控制器
 */
@RestController
@RequestMapping("/hospital")
public class HospitalInfoController {

    @Resource
    private HospitalInfoService hospitalInfoService;

    @Resource
    private StaffService staffService;

    /**
     * 获取医院基本信息
     */
    @GetMapping("/info")
    public Result<Map<String, Object>> getHospitalInfo() {
        Map<String, Object> info = hospitalInfoService.getHospitalInfo();
        return Result.success(info);
    }

    /**
     * 获取医生列表
     */
    @GetMapping("/staff")
    public Result<Page<Staff>> getStaffList(
            @RequestParam(required = false) Long departmentId,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        Page<Staff> staffPage = staffService.getStaffList(departmentId, page, size);
        return Result.success(staffPage);
    }

    /**
     * 获取医生详情
     */
    @GetMapping("/staff/{id}")
    public Result<Staff> getStaffDetail(@PathVariable Long id) {
        Staff staff = staffService.getById(id);
        return Result.success(staff);
    }

    /**
     * 添加评价
     */
    @PostMapping("/review")
    public Result<Long> addReview(@RequestBody @Valid ReviewDTO reviewDTO, HttpServletRequest request) {
        Long userId = (Long) request.getAttribute("userId");
        Long reviewId = hospitalInfoService.addReview(reviewDTO, userId);
        return Result.success(reviewId);
    }

    /**
     * 获取医生评价列表
     */
    @GetMapping("/review/staff/{staffId}")
    public Result<Page<Review>> getStaffReviews(
            @PathVariable Long staffId,
            @RequestParam(defaultValue = "1") int page,
            @RequestParam(defaultValue = "10") int size) {
        Page<Review> reviewPage = hospitalInfoService.getStaffReviews(staffId, page, size);
        return Result.success(reviewPage);
    }
} 